package com.aos.service;


import com.aos.dao.UserDao;
import com.aos.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by quxiaoyan.
 */
@Service
public class UserServiceDetail implements UserDetailsService {

    @Autowired
    private UserDao userRepository;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        System.out.println("=====loadUserByUsername:" + username);
        return userRepository.findByUid(Long.parseLong(username));
//        User user = userRepository.findByUid(Long.parseLong(username));
//        List<GrantedAuthority> roleList = new ArrayList<>();
//        roleList.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
//        return new org.springframework.security.core.userdetails.User(user.getUsername(),user.getPassword(),roleList);
    }

}
